/**
 * Created by dqw on 2015/12/30.
 */

//列表开始
var dtGridColumns = [
    {
        id: 'delFlag',
        type: 'int',
        hideQuery:true,
        'export':false,
        hideQueryType:'eq',
        hideQueryValue:1,
        hide:true

    },
    {
        id: 'id',
        title: '编号',
        type: 'number',
        headerClass: 'text-center width-50',
        columnClass: 'text-center width-50',
        fastSort: true,
        fastQuery: false
    },
    {
        id: 'exceptionOrderNum',
        title: '收款订单号',
        type: 'string',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'exactPaymentBank',
        title: '实际支付的银行编码',
        type: 'string',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'payCardName',
        title: '付款用户名',
        type: 'string',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: true,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'payCardNum',
        title: '付款卡号',
        type: 'string',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: true,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'receivingBank',
        title: '收款银行',
        type: 'string',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: true,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'receivingAccountName',
        title: '收款卡账户名',
        type: 'string',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: true,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'channel',
        title: '交易渠道',
        type: 'string',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: true,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'note',
        title: '附言',
        type: 'string',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: true,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'area',
        title: '交易地区',
        type: 'string',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: true,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'fee',
        title: '手续费',
        type: 'string',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: true,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'transactionCharge',
        title: '服务费',
        type: 'string',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: true,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'amount',
        title: '实际到账金额',
        type: 'string',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: true,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'exactTime',
        title: '实际到账时间',
        type: 'date',
        format: 'yyyy-MM-dd hh:mm:ss',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: true,
        fastQuery: true,
        fastQueryType: 'range'
    },
    {
        id: 'excDealStatus',
        title: '状态',
        type: 'int',
        headerClass: 'text-center width-200',
        columnClass: 'text-left width-200',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'eq',
        codeTable: {
            1: $lang.excDealStatus.T1,
            2: $lang.excDealStatus.T2
        }
    },
    {
        id: 'operation',
        title: '标记处理',
        type: 'string',
        headerClass: 'text-center width-100',
        columnClass: 'text-center width-100',
        fastSort: false,
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var html="",
                state = "";
            if (record.excDealStatus == 1) {
                if ($("#rechargeExcMark") && $("#rechargeExcMark").val() == 1) {
                    state = "<a href='javascript:;' class='btn btn-danger btn-sm m-r-10' onclick='OperateHandle.mark(" + record.id + ",\"" + 2+ "\",\"" + record.exceptionOrderNum + "\")'><i class='fa fa-plus'></i>&nbsp;标记已处理&nbsp;</a>";
                }
            } else {
                return "";
            }
            html =  state;
            return html;
        }
    }
];

var dtGridOption = {
    lang: 'zh-cn',
    ajaxLoad: true,
    loadURL: ncGlobal.adminRoot + 'rechargeExc/json/list',
    exportFileName: '异常充值订单',
    columns: dtGridColumns,
    gridContainer: 'dtGridContainer',
    toolbarContainer: 'dtGridToolBarContainer',
    tools: 'refresh|faseQuery',
    pageSize: 10,
    pageSizeLimit: [10, 20, 50]
};

var grid = $.fn.DtGrid.init(dtGridOption);
grid.fastQueryParameters = new Object();
grid.fastQueryParameters['eq_delFlag'] = 1;

//排序
grid.sortParameter.columnId = ['asc_excDealStatus'];
//列表结束

//操作处理开始
var OperateHandle = function () {

    function _bindEvent() {
        //模糊搜索
        $('#customSearch').click(function () {
            grid.fastQueryParameters = new Object();
            grid.fastQueryParameters['eq_delFlag'] = 1;
            grid.fastQueryParameters['lk_exceptionOrderNum'] = $('#keyword').val();
            grid.pager.startRecord = 0;
            grid.pager.nowPage = 1;
            grid.pager.recordCount = -1;
            grid.pager.pageCount = -1;
            grid.refresh(true);
        });
    }

    var stateUrl = ncGlobal.adminRoot + "rechargeExc/json/mark";
    function _mark(id,status, content) {
        var tpl = '您选择对异常订单 <strong>' + content + '</strong>进行标记已处理操作。<br/>您确定要进行该操作吗?'
        $.ncConfirm({
            url: stateUrl,
            data: {
                id: id
            },
            content: tpl,
            alertTitle: "标记处理操作"
        });
    }
    //外部可调用
    return {
        bindEvent: _bindEvent,
        mark: _mark,
    }

}();
//操作处理结束

$(function () {
    //加载列表
    grid.load();
    //页面绑定事件
    OperateHandle.bindEvent();
});